//author: create by SunJH
//时间: 2021/12/14 0014
//邮箱: 965989158@qq.com
//描述: 极光推送的控制器

import 'package:flutter_app/utils/jg_util.dart';
import 'package:flutter_app/utils/log_util.dart';
import 'package:get/get.dart';
import 'package:jpush_flutter/jpush_flutter.dart';

class JgTestController extends GetxController {
  var isOpenJG = true.obs;
  var jPush = JGUtil.instance.getJPush;

  var jGAlias = "".obs;
  var tags = <String>[].obs;

  @override
  void onInit() {


    // jPush.getRegistrationID().then((value){
    //   LogUtil.logI("调用注册方法getRegistrationID获取到的值:$value");
    // });
  }
  sendLocalNotification(){
    jPush.isNotificationEnabled().then((bool value) {
        print("通知是否打开${value}");
    });
    var localNotification = LocalNotification(
        id: 234,
        title: 'fadsfa',
        buildId: 1,
        content: 'fdas',
        fireTime: DateTime.now(),
        subtitle: 'fasf',
        badge: 5,
        extra: {"fa": "0"});
    jPush.sendLocalNotification(localNotification);
  }
  addTag(String tag) {
    tags.add(tag);
        jPush.addTags(tags).then((value) => LogUtil.logI(value));
  }

  deleteTag(String tag){
    tags.remove(tag);
    jPush.deleteTags(tags).then((value) => LogUtil.logI(value));
  }

  clearTag(){
    tags.clear();
    jPush.setTags(tags);
  }

  setJGAlias() {
    jPush.setAlias(jGAlias.value).then((value) => {LogUtil.logI(value)});
  }

  deleteAlias() {
    jGAlias.value = "";
    jPush.deleteAlias().then((value) => {LogUtil.logI(value)});
  }
}
